package com.xjy.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportLoanRecord;
import com.xjy.system.domain.ReportPrepaymentDetail;
import com.xjy.system.domain.bo.ReportPrepaymentDetailQueryBo;
import com.xjy.system.domain.vo.ReportPrepaymentDetailVo;
import com.xjy.system.mapper.ReportPrepaymentDetailMapper;
import com.xjy.system.service.IReportPrepaymentDetailService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 预付款明细表Service业务层处理
 *
 * @author mlb
 * @date 2022-03-24
 */
@Service
public class ReportPrepaymentDetailServiceImpl extends ServicePlusImpl<ReportPrepaymentDetailMapper, ReportPrepaymentDetail> implements IReportPrepaymentDetailService {

    @Override
    public ReportPrepaymentDetailVo queryById(Long projId){
        return getVoById(projId, ReportPrepaymentDetailVo.class);
    }

    @Override
    public TableDataInfo<ReportPrepaymentDetailVo> queryPageList(ReportPrepaymentDetailQueryBo bo) {
        PagePlus<ReportPrepaymentDetail, ReportPrepaymentDetailVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportPrepaymentDetailVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportPrepaymentDetailVo> queryList(ReportPrepaymentDetailQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportPrepaymentDetailVo.class);
    }

    private LambdaQueryWrapper<ReportPrepaymentDetail> buildQueryWrapper(ReportPrepaymentDetailQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportPrepaymentDetail> lqw = Wrappers.lambdaQuery();
        lqw.like(StrUtil.isNotBlank(bo.getProjName()), ReportPrepaymentDetail::getProjName, bo.getProjName());
        lqw.eq(StrUtil.isNotBlank(bo.getAdvanceColer()), ReportPrepaymentDetail::getAdvanceColer, bo.getAdvanceColer());
		lqw.eq(null != bo.getProjId(), ReportPrepaymentDetail::getProjId,bo.getProjId());
		lqw.eq(null != bo.getAdvanceColId(), ReportPrepaymentDetail::getAdvanceColId,bo.getAdvanceColId());

		lqw.between(params.get("beginPrepayDate") != null && params.get("endPrepayDate") != null,
            ReportPrepaymentDetail::getPrepayDate ,params.get("beginPrepayDate"), params.get("endPrepayDate"));
        return lqw;
    }
}
